﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using WLYT.Admin.WebApi.Component.Quartz;

namespace WLYT.Admin.WebApi.Controllers
{
    //[System.Web.Http.Description.ApiExplorerSettings(IgnoreApi = true)]
    public class TaskController : ApiController
    {
        /// <summary>
        /// 创建任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [Route("api/Task/CreadTask")]
        public Task<bool> CreadTask(string taskName)
        {
            SchedulerCenter scheduleCenter = new SchedulerCenter();
            return scheduleCenter.AddTaskAsync(new Domain.Model.Task { TaskName = taskName, CronExpress = "0/5 * * * * ?" });
        }

        /// <summary>
        /// 恢复任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [Route("api/Task/ResumeTask")]
        public Task<bool> ResumeTask(string taskName)
        {
            SchedulerCenter scheduleCenter = new SchedulerCenter();
            return scheduleCenter.ResumeTaskAsync(taskName);
        }

        /// <summary>
        /// 暂定任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [Route("api/Task/StopTask")]
        public Task<bool> StopTask(string taskName)
        {
            SchedulerCenter scheduleCenter = new SchedulerCenter();
            return scheduleCenter.StopTaskAsync(taskName);
        }

        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [Route("api/Task/DeleteTask")]
        public Task<bool> DeleteTask(string taskName)
        {
            SchedulerCenter scheduleCenter = new SchedulerCenter();
            return scheduleCenter.DeleteTaskAsync(taskName);
        }
    }
}